// pages/peccancy/peccancy-list.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
		loading:false
    },

    onLoad: function(options) {
        this.setData({
            carObj: options
        })
        this.loadData()
    },
    loadData() {
        wx.showLoading({
            title: '加载中...',
        })
		if(this.data.loading) return
		this.setData({
			loading:true
		})
        app.http.post('rest/violation/getViolations.do', {
            data: this.data.carObj
        }).then(res => {
			let violations = 0,points = 0,fines = 0
			for(let i = 0;i<res.obj.length;i++){
				points += res.obj[i].point
				fines += res.obj[i].fines
			}
            this.setData({
                list: res.obj,
				violations:res.obj.length,
				points,
				fines,
				loading:false
            })
            wx.hideLoading()
        }).catch(err => {
            wx.hideLoading()
			this.setData({
				loading:false
			})
            app.wxToast.error(err.data.msg)
        })
    },
    toAgency() {
        let carObj = this.data.carObj
        let paramsArr = []
        Object.keys(carObj).forEach(k => {
            paramsArr.push(k + "=" + carObj[k])
        })
        wx.navigateTo({
            url: '/pages/car-owner/peccancy/check-agency' + '?' + paramsArr.join('&'),
        })
    }
})